package com.woniuxy.intellihome.controller.admin;


import com.woniuxy.intellihome.entity.ResponseEntity;
import com.woniuxy.intellihome.entity.Spec;
import com.woniuxy.intellihome.entity.SpecDetail;
import com.woniuxy.intellihome.service.SpecDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-08-11
 */
@RestController
@Slf4j
@RequestMapping("admin/specDetail")
public class SpecDetailController {
    @Autowired
    private SpecDetailService detailService;

    @RequestMapping("add")
    public ResponseEntity<SpecDetail> add(String specId,String specValue){
        SpecDetail specDetail = new SpecDetail();
        specDetail.setSpecId(Integer.parseInt(specId));
        specDetail.setSpecValue(specValue);
        specDetail.setStatus("y");
        log.debug("add spec:{}",specDetail);
        detailService.save(specDetail);
        return new ResponseEntity<>(specDetail);
    }

    //上下架
    @RequestMapping("upDown")
    public ResponseEntity<SpecDetail> changeStatus(int id){
        SpecDetail specDetail = detailService.getById(id);
        if("y".equals( specDetail.getStatus())){
            specDetail.setStatus("n");
        }else{
            specDetail.setStatus("y");
        }
        detailService.updateById(specDetail);
        return new ResponseEntity<>(specDetail);
    }

}

